package com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount {
	private double overdraft;
	
	public double getOverdraft() {
		return overdraft;
	}
	
	public void setOverdraft(double overdraft) {
		this.overdraft = overdraft;
	}
	
	public CheckingAccount(double balance) 
	{
		setBalance(balance);
		overdraft = 0;
	}
	
	public CheckingAccount(double balance, double overdraft) 
	{
		setBalance(balance);
		this.overdraft = overdraft;
	}
	
	@Override
	public void deposit(double x) 
	{
		setBalance(getBalance() + x);
	}
	
	@Override
	public void withdraw(double x) {
	/*		
 		double balance = getBalance();
		if (balance >= x) 
		{
			setBalance(balance - x);
		} 
		else if (balance + overdraft >= x) 
		{
			overdraft -= ( x - balance );
			setBalance(0);
		}
		else
		{
			//exception: not enough money
		}
	*/
		if ( x > getBalance() ) {
			overdraft -= (x - getBalance());
			setBalance(0);			
		}
		else
		{
			setBalance(getBalance() - x);
		}
		assert getBalance() > 0;
	}

	@Override
	public double maximumAmountToWithdraw() {
		return getBalance()+getOverdraft();
	}

}
